// pages/livemanage/livemanage.js

import { reqIMUserCreate } from '../../api/livemanage'
import {reqCustomerInfo} from '../../api/profile'

import {getStorage} from '../../utils/storage'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    avatarUrl:'',
    nickName:''
  },

  onShow(){
    this.getAnchorInfo()
  },

  async getAnchorInfo(){
    const{data} = await reqCustomerInfo()
    this.setData({
      avatarUrl:data.customerAvatar,
      nickName:data.customerName
    })
  },

  navigateToMinimall(){
    wx.navigateTo({
      url:'/pages/minimall/minimall'
    })
  },

  navigatoToLive(){
    this.createIM()
    wx.navigateTo({
      url: '/pages/live/live',
    })
  },

  async createIM(){
    const openid = getStorage('openId')
    const param ={
      "openId":openid,
      "nickName":this.data.nickName,
      "avatarUrl":this.data.avatarUrl
    }

    const {data} = await reqIMUserCreate(param)
    // console.log(data)
  },

  navigateToLiveCheckout(){
    wx.navigateTo({
      url: '/pages/live_checkout/live_checkout',
    })
  }

})